﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Main.lib.graphics
{

    /*
     * Sprite (DisplayObject)
     * 
     * @brief   Let you draw an image on the screen
     * @version 2011.11.14
     * 
     * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
     */
    public sealed class Sprite : DisplayObject
    {

     // Scope  Type      Name      Value
        public Texture2D Texture = null; //!< Image which will be drawn

        /*
         * Constructor
         * 
         * @param [OPTIONAL] (Texture2D) NewTexture - The image
         */
        public Sprite(Texture2D NewTexture = null)
        {
            Texture = NewTexture;
        }

        /*
         * Draw the image on the screen
         * 
         * @warning This method is called automatically
         * @param   (SpriteBatch) SpriteBatch - Context which the image will be drawn
         */
        public override void Draw(SpriteBatch SpriteBatch)
        {
            if ((Invisible) || (Texture == null))
                return;
            SpriteBatch.Draw(Texture, Position, Rectangle, Color, Rotation, Origin, Scale, Effects, LayerDepth);
        }

        /*
         * Erase the image
         */
        public override void Dispose()
        {
            base.Dispose();
            Texture = null;
        }

        /*
         * Get the bounds of the sprite
         * 
         * @return (Rectangle) - Position and size of the image
         */
        public Rectangle Bounds
        {
            get
            {
                if (Texture == null)
                    return new Rectangle((int)Position.X, (int)Position.Y, 0, 0);
                return new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height);
            }
        }

        public Vector2 Size()
        {
            return new Vector2(Bounds.Width, Bounds.Height);
        }

    }

}